<?php
class VastHelper 
{
    static function getHosocanbo()
    {
		$user = JFactory::getUser();
        $id = $user->id;

        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select('DISTINCT a.*');
        $query->from('#__hosocanbo AS a');
        $query->where('a.nguoidung_id = ' . $id);

        $db->setQuery($query);
        $canbo = $db->loadObject();

        return $canbo;        
    }     
    
    static function getPhongLanhDao()
    {
		$user = JFactory::getUser();
        $id = $user->id;

        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select('DISTINCT a.*, c.id AS phongid');
        $query->from('#__hosocanbo AS a');
        $query->join('INNER', '#__congtac AS b ON b.hosocanbo_id = a.id');
        $query->join('INNER', '#__phong AS c ON c.id = b.phong_id');
        
        $query->where('a.nguoidung_id = ' . $id);
        $query->where('b.lanhdao = 1 AND b.taivi = 1');

        $db->setQuery($query);
        $result = $db->loadObject();
        
        return $result;        
    }       
    
    static function getDonViLanhDao()
    {
		$user = JFactory::getUser();
        $id = $user->id;

        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select('DISTINCT a.*, c.id AS donviid');
        $query->from('#__hosocanbo AS a');
        $query->join('INNER', '#__congtac AS b ON b.hosocanbo_id = a.id');
        $query->join('INNER', '#__donvi AS c ON c.id = b.donvi_id');
        
        $query->where('a.nguoidung_id = ' . $id);
        $query->where('b.lanhdao = 1 AND b.taivi = 1');

        $db->setQuery($query);
        $result = $db->loadObject();
        
        return $result;        
    }    
    
    static function getPhongTrucThuoc($hosocanboid)
    {
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select('DISTINCT a.*, c.id AS phongid');
        $query->from('#__hosocanbo AS a');
        $query->join('INNER', '#__congtac AS b ON b.hosocanbo_id = a.id');
        $query->join('INNER', '#__phong AS c ON c.id = b.phong_id');
        
        $query->where('a.id = ' . $hosocanboid);
        $query->where('b.taivi = 1');

        $db->setQuery($query);
        $result = $db->loadObject();
        
        return $result;                
    }

    static function getDonViTrucThuoc($hosocanboid)
    {
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select('DISTINCT a.*, c.id AS donviid');
        $query->from('#__hosocanbo AS a');
        $query->join('INNER', '#__congtac AS b ON b.hosocanbo_id = a.id');
        $query->join('INNER', '#__donvi AS c ON c.id = b.donvi_id');
        
        $query->where('a.id = ' . $hosocanboid);
        $query->where('b.taivi = 1');

        $db->setQuery($query);
        $result = $db->loadObject();
        
        return $result;                
    }

}